package com.hp.attendance.serlvet.overtime;

import com.hp.attendance.entity.Overtime;
import com.hp.attendance.service.OvertimeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

@WebServlet("/addOvertime")
public class OvertimeAddServlet extends HttpServlet {
    private OvertimeService overtimeService = new OvertimeService();

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//获取页面数据
        Date date = new Date();
        try {
            String depname = req.getParameter("department_number");
            String empname = req.getParameter("employee_number");
            String dateTime = req.getParameter("date");
            date = new SimpleDateFormat("yyyy-MM-dd").parse(dateTime);

            Overtime overtime = new Overtime();
            overtime.setDepartment_number(Integer.valueOf(depname));
            overtime.setEmployee_number(Integer.valueOf(empname));
            overtime.setDay(date);
            overtime.setId(null);
            overtime.setStart_time(null);
            overtime.setEnd_time(null);
            overtime.setNotes(null);
            overtimeService.addOvertime(overtime);
            req.getRequestDispatcher("/overtimeList").forward(req, resp);
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

}
